#include "glink.h"

#ifdef GLINK_ENABLE
using namespace glink;

void glink::GLink::setParams(uint8 des_id, uint8 des_c, uint8 needReq, uint8 addr_mod, uint8 wait_level, uint8 dsitance)
{
	des_id_ = des_id;
	des_c_ = des_c;	
	needReq_ = needReq;
	addr_mod_ = addr_mod;
	wati_level_ = wait_level;
	dsitance_ = dsitance;
}

void glink::GLink::setDesId(uint8 des_id)
{
	des_id_ = des_id;
}

void glink::GLink::setDesC(uint8 des_c)
{
	des_c_ = des_c;
}

void glink::GLink::setNeedReq(uint8 needReq)
{
	needReq_ = needReq;
}

void glink::GLink::setAddrMod(uint8 addr_mod)
{
	addr_mod_ = addr_mod;
}

void glink::GLink::setWaitLevel(uint8 wati_level)
{
	wati_level_ = wati_level;
}

void glink::GLink::setDsitance(uint8 dsitance)
{
	dsitance_ = dsitance;
}

void glink::GLink::setMessageCallback(GLinkMessageCallback callback)
{
	response_.setMessageCallback(callback);
}

short glink::GLink::send(uint16 byte_addr, uint16* pData, uint16 word_num)
{
	assert(word_num <= max_send_len_);
	return RN_ComHandler(1, 0x01, byte_addr, (short*)pData, word_num,
		des_id_, des_c_, needReq_, addr_mod_, wati_level_, dsitance_);
}

short glink::GLink::read(uint16 byte_addr, uint16* pData, uint16 word_num)
{
	assert(word_num <= max_send_len_);
	return RN_ComHandler(1, 0x05, byte_addr, (short*)pData, word_num,
		des_id_, des_c_, needReq_, addr_mod_, wati_level_, dsitance_);
}

short glink::GLink::rnComHandler(uint8 mode, uint8 cmd, uint16 byte_addr, uint16 * pData,
	uint16 word_num, uint8 des_id, uint8 des_c, uint8 needReq, uint8 addr_mod, uint8 wait_level, uint8 dsitance)
{
	assert(word_num <= max_send_len_);
	return RN_ComHandler(mode, cmd, byte_addr, (short*)pData, word_num, des_id,
		des_c, needReq, addr_mod, wait_level, dsitance);
}
#endif // GLINKE_ENABLE
